package com.zto.sch.base.proxy;

import sun.misc.ProxyGenerator;

import java.io.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2020-12-06 23:07
 **/
public class ProxtTest {
    /**
     * 模拟生成动态代理.class文件
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        UserService userService = (UserService) Proxy.newProxyInstance(ProxtTest.class.getClassLoader(), new Class[]{UserService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("哈哈");

                return null;
            }
        });


        byte[] $UserServices = ProxyGenerator.generateProxyClass("$UserService", new Class[]{UserService.class});

        FileOutputStream fos = new FileOutputStream(new File("/Users/sch/mydocument/temp/$UserServices.class"));
        fos.write($UserServices);


    }
}
